package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Businesstype;
import com.restaurant.service.BusinesstypeService;

public class BusinesstypeServiceImpl implements BusinesstypeService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Businesstype addOrModify( Businesstype objBusinesstype ) {
       return ( Businesstype ) hibernateTemplate.merge( objBusinesstype );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Businesstype deleteRecord( Businesstype objBusinesstype ) {
       hibernateTemplate.delete( objBusinesstype );
       return objBusinesstype;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Businesstype modifyRecord( Businesstype objBusinesstype ) {
       return ( Businesstype ) hibernateTemplate.merge( objBusinesstype );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Businesstype> loadAll() {
       return (List<Businesstype>)hibernateTemplate.findByNamedQuery( "Businesstype.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Businesstype loadByPrimaryKey( Long primaryKey ) {
       return (Businesstype) hibernateTemplate.get( Businesstype.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Businesstype deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Businesstype> loadByHql(String query) {
       return ( List<Businesstype> ) hibernateTemplate.find( query );
   }
}